package org.huawei260.TiKu.ODsuanfa;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;
public class A_2023A_2600__栈括号检查 {

//	public class Main {
		// 输入获取
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			String s = sc.nextLine();
			System.out.println(getResult(s));
		}

		// 算法入口
		public static int getResult(String s) {
			HashMap<Character, Character> map = new HashMap<>();
			map.put(')', '(');
			map.put(']', '[');
			map.put('}', '{');

			LinkedList<Character> stack = new LinkedList<>();

			int maxDepth = 0;
			for (int i = 0; i < s.length(); i++) {
				char c = s.charAt(i);

				if (stack.size() > 0 && map.get(c) == stack.getLast()) {
					stack.removeLast();
				} else {
					stack.add(c);
					maxDepth = Math.max(maxDepth, stack.size());
				}
			}

			if (stack.size() > 0) return 0;
			return maxDepth;
		}
	}